<?php
/**
 * Created by JetBrains PhpStorm.
 * User: shaoshuai
 * Date: 12-7-16
 * Time: 下午8:34
 */
include 'boot.php';
session_start();
$myName = $_SESSION['username'];

//create room
$room = Room::create();
$room->setGuest(new User(array('name' => $myName)));
$_SESSION['room'] = $room->getId();

$acceptWhom = new User(array('name' => $_GET['accept']));
$acceptWhom->setData('room', $room->getId());
$event = new Event(array(
    'type' => Event::FIGHT_ACCEPT,
    'from' => $myName,
));
EventDispatcher::dispatch($acceptWhom, $event);

$room->save();
$_SESSION['role'] = 'guest';
$output = array(
    'success' => true,
);
echo json_encode($output);
